FROM registry.cn-hangzhou.aliyuncs.com/xiaoyilin/java17:0.17-d131slim
ARG K_V
ADD kafka_2.13-${K_V}.tgz /usr/local/
WORKDIR /usr/local/kafka_2.13-${K_V}
RUN KAFKA_CLUSTER_ID="$(bin/kafka-storage.sh random-uuid)" && \
bin/kafka-storage.sh format -t $KAFKA_CLUSTER_ID -c config/kraft/server.properties && \
sed -i "s/#listeners=PLAINTEXT:\/\/:9092/listeners=PLAINTEXT:\/\/0.0.0.0:9092/g" config/kraft/server.properties && \
touch init.shell && echo "#!/bin/bash" >> init.shell && \
echo "kafka-topics.sh --create --topic test-topic --bootstrap-server localhost:9092" >> init.shell && \
echo "kafka-topics.sh --describe --topic test-topic --bootstrap-server localhost:9092" >> init.shell && \
chmod +x init.shell
ENV KAFKA_HOME=/usr/local/kafka_2.13-${K_V}
ENV PATH=$KAFKA_HOME/bin:$PATH
CMD ["kafka-server-start.sh","config/kraft/server.properties"]


# docker build  --build-arg K_V=3.9.1 -t registry.cn-hangzhou.aliyuncs.com/xiaoyilin/kafka:3.9.1 .
# docker run --rm registry.cn-hangzhou.aliyuncs.com/xiaoyilin/kafka:3.9.1
# docker run -d -p 9092:9092 --rm registry.cn-hangzhou.aliyuncs.com/xiaoyilin/kafka:3.9.1
# docker push registry.cn-hangzhou.aliyuncs.com/xiaoyilin/kafka:3.9.1